package com.jingyanzi.privilege.client;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jingyanzi.finance.result.ResultSupport;
import com.jingyanzi.privilege.domain.EmployeeDO;
import com.jingyanzi.privilege.domain.result.ResultDO;
import com.jingyanzi.privilege.query.EmployeeQueryDO;
import com.jingyanzi.privilege.service.IEmployeeService;

@RestController
@RequestMapping("/api")
public class EmployeeClientImpl implements EmployeeClientAPI {
	@Autowired
	IEmployeeService employeeService;

	@GetMapping("/employee/{id}")
	public EmployeeDO get(@PathVariable(value = "id") Integer id) {
		ResultDO result  = employeeService.getEmployee(id);
		return (EmployeeDO) result.getModel(ResultSupport.FIRST_MODEL_KEY);
	}
	
	@GetMapping("/employees/{realName}/{code}/{jobsId}/{mobile}")
	public List<EmployeeDO> query(@PathVariable(value = "realName") String realName,
			@PathVariable(value = "code") String code, @PathVariable(value = "jobsId")  Integer jobsId, @PathVariable(value = "mobile") String mobile) {
		
		EmployeeQueryDO query = new EmployeeQueryDO();
		
		if(realName.toLowerCase().equals("all")) {
			query.setRealName(null);
		} else {
			query.setRealName(realName);
		}
		if(mobile.toLowerCase().equals("all")) {
			query.setMobile(null);
		} else {
			query.setMobile(mobile);
		}
		if(code.toLowerCase().equals("all")) {
			query.setCode(null);
		} else {
			query.setCode(code);
		}
		query.setJobsId(jobsId);
		query.setCheckCashier(0);
		ResultDO result  = employeeService.queryEmployeeByCode(query);
		return (List<EmployeeDO>) result.getModel(ResultSupport.FIRST_MODEL_KEY);
	}
	
}